# encoding    : utf-8
# author      : 伦裕如
# project     : hrjt_-py1
# file        : patten1
# time        : 2024-06-19 下午4:14
import pymysql


# 用来管理数据库操作
class DatabaseManage:

    def __init__(self, user = 'root', password = 'root', database = 'jiangsu',
                 host = 'localhost', port = 3306, charset = 'utf8'):
        self.user = user
        self.password = password
        self.database = database
        self.host = host
        self.port = port
        self.charset = charset
        self.connection = None
        self.cursor = None


    def connect(self):
        try:
            # 建立数据库连接
            self.connection = pymysql.connect(
                host = self.host,
                port = self.port,
                user = self.user,
                password = self.password,
                database = self.database,
                charset = self.charset
            )

            self.cursor = self.connection.cursor()
            self.cursor.execute()
        except Exception as e:
            print(f'数据库连接异常{e}')


